#pragma once
#include <Windows.h>

namespace WinTools
{
	class CMutex
	{
	public:
		CMutex();
		~CMutex();

		/// <summary>
		/// Locks the CRITICAL_SECTION.
		/// </summary>
		/// <returns></returns>
		void Lock();

		/// <summary>
		/// Unlocks the CRITICAL_SECTION.
		/// </summary>
		/// <returns></returns>
		void Unlock();

		/// <summary>
		/// Tries to lock the CRITICAL_SECTION.
		/// </summary>
		/// <returns>
		/// TRUE	= The CRITICAL_SECTION has successfully been locked.
		/// FALSE	= Failed to lock the CRITICAL_SECTION.
		/// </returns>
		bool TryLock();

		/// <summary>
		/// Checks whether the CRITICAL_SECTION is locked.
		/// </summary>
		/// <returns>
		/// TRUE	= The CRITICAL_SECTION is already locked.
		/// FALSE	= The CRITICAL_SECTION is not locked.
		/// </returns>
		bool IsLocked();

	private:
		CRITICAL_SECTION m_Mutex;
	};
}

